//
//  NSString+HtmlCss.m
//  WDFans
//
//  Created by Ryan on 13-1-6.
//
//

#import "NSString+HtmlCss.h"

@implementation NSString (HtmlCss)


+ (NSString *)adjustHtmlCSSForString:(NSString *)originalString
{
    // Adjust the CSS style of saved html file
    NSString *html = @"";
    NSString *adjustedHtml = @"";
    NSString *infoFilePath = [[NSBundle mainBundle] pathForResource:@"htmlTemplate" ofType:@"html"];
    adjustedHtml = [NSString stringWithContentsOfFile:infoFilePath encoding: NSUTF8StringEncoding error:nil];
    
    html = originalString;
        
//    if ([html rangeOfString:@"<div id='docbody'>"].location != NSNotFound)
//    {
//        if ([html rangeOfString:@"</body>"].location != NSNotFound)
//        {
//            NSUInteger startIndex = -1;
//            NSUInteger endIndex = -1;
//            startIndex = (NSUInteger)[html rangeOfString:@"<div id='docbody'>"].location;
//            endIndex = (NSUInteger)[html rangeOfString:@"</body>"].location;
//            NSRange range = NSMakeRange(startIndex, endIndex - startIndex);
//            NSString *bodyPart = [html substringWithRange:range];
    
    NSString *bodyPart = html;
    NSString *ajustedBodyPart = bodyPart;
            ajustedBodyPart = [ajustedBodyPart stringByReplacingOccurrencesOfString:@"\"width" withString:@"\"nonwidth"];
            ajustedBodyPart = [ajustedBodyPart stringByReplacingOccurrencesOfString:@" width" withString:@" nonwidth"];
            ajustedBodyPart = [ajustedBodyPart stringByReplacingOccurrencesOfString:@";width" withString:@";nonwidth"];
            ajustedBodyPart = [ajustedBodyPart stringByReplacingOccurrencesOfString:@"\"height" withString:@"\"nonheight"];
            ajustedBodyPart = [ajustedBodyPart stringByReplacingOccurrencesOfString:@" height" withString:@" nonheight"];
            ajustedBodyPart = [ajustedBodyPart stringByReplacingOccurrencesOfString:@";height" withString:@";nonheight"];
            
            ajustedBodyPart = [ajustedBodyPart stringByReplacingOccurrencesOfString:@"\"margin-left" withString:@"\"nonmargin-left"];
            ajustedBodyPart = [ajustedBodyPart stringByReplacingOccurrencesOfString:@" margin-left" withString:@" nonmargin-left"];
            ajustedBodyPart = [ajustedBodyPart stringByReplacingOccurrencesOfString:@";margin-left" withString:@";nonmargin-left"];
            ajustedBodyPart = [ajustedBodyPart stringByReplacingOccurrencesOfString:@"\"margin-right" withString:@"\"nonmargin-right"];
            ajustedBodyPart = [ajustedBodyPart stringByReplacingOccurrencesOfString:@" margin-right" withString:@" nonmargin-right"];
            ajustedBodyPart = [ajustedBodyPart stringByReplacingOccurrencesOfString:@";margin-right" withString:@";nonmargin-right"];
            
            ajustedBodyPart = [ajustedBodyPart stringByReplacingOccurrencesOfString:@"text-indent" withString:@"nontext-indent"];
            
            adjustedHtml = [adjustedHtml stringByReplacingOccurrencesOfString:@"%@" withString:ajustedBodyPart];
//        }
//    }
    return adjustedHtml;
}


@end
